//
//  SystemAlertView.m
//  DaleTou
//
//  Created by wenrong on 2018/6/1.
//  Copyright © 2018年 geren. All rights reserved.
//

#import "SystemAlertView.h"

@implementation SystemAlertView
+ (void)alertWithTitle:(NSString *) title
               message:(NSString *) message
        preferredStyle:(UIAlertControllerStyle) style
            actionBtns:(NSArray *) btns
                target:(UIViewController *) controller
         btnClickBlock:(void (^) (NSString *actionTitle)) block
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:style];
    for (NSString *btnTitle in btns) {
        UIAlertActionStyle tempStyle = UIAlertActionStyleDefault;
        if (!btnTitle) {
            return;
        }
        if ([btnTitle isEqualToString:@"取消"]) {
            tempStyle = UIAlertActionStyleCancel;
        }
        UIAlertAction *action = [UIAlertAction actionWithTitle:btnTitle style:tempStyle handler:^(UIAlertAction * _Nonnull action) {
            if (block && action.style != UIAlertActionStyleCancel) {
                block(action.title);
            }
        }];
        [alert addAction:action];
    }
    [controller presentViewController:alert animated:YES completion:nil];
}
@end
